#pragma once
#include"Hash.h"
namespace jlf
{
	
	template<class K, class Hash = HashFunc<K>>
	class unordered_set
	{
		
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename 
			hash_bucket::HashTable<K, const K, SetKeyOfT, Hash>
			::Iterator iterator;
		typedef typename 
			hash_bucket::HashTable<K, const K, SetKeyOfT, Hash>::
			ConstIterator const_iterator;


		iterator begin() 
		{
			return _ht.Begin(); 
		}
		iterator end() 
		{
			return 	_ht.End(); 
		}

		const_iterator begin() const 
		{
			return _ht.Begin();
		}
		const_iterator end() const
		{
			return 	_ht.End();
		}
	
		// capacity
		size_t size() const
		{ 
			return _ht.Size(); 
		}

		bool empty() const 
		{ 
			return _ht.Empty(); 
		}
		
		// lookup
		iterator find(const K& key) 
		{
			return _ht.Find(key); 
		}
		size_t count(const K& key) 
		{
			return _ht.Count(key);
		}
		
		// modify
		pair<iterator, bool> insert(const K& valye)
		{
			return _ht.Insert(valye);
		}

		iterator erase(iterator position)
		{
			return _ht.Erase(position);
		}
		
		// bucket
		size_t bucket_count() 
		{ 
			return _ht.BucketCount();
		}
		size_t bucket_size(const K& key) 
		{ 
			return _ht.BucketSize(key); 
		}
	private:
		hash_bucket::HashTable<K, const K, SetKeyOfT, Hash> _ht;
	};
	void print(const unordered_set<int>& s)
	{
		unordered_set<int>::const_iterator it = s.begin();
		while (it != s.end())
		{
			//*it = 1;
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : s)
		{
			cout << e << " ";
		}
		cout << endl;
	}

	void test_set1()
	{
		int a[] = { 3,11,86,7,88,82,1,881,5,6,7,6 };
		unordered_set<int> s;
		for (auto e : a)
		{
			s.insert(e);
		}

		unordered_set<int>::iterator it = s.begin();
		while (it != s.end())
		{
			//*it = 1;
			cout << *it << " ";
			++it;
		}
		cout << endl;

		for (auto e : s)
		{
			cout << e << " ";
		}
		cout << endl;

		print(s);
		cout << "s.size() :" << s.size() << endl;

		cout << "s.bucket_count():" << s.bucket_count() << endl;
		cout << "s.bucket_size(3):" << s.bucket_size(3) << endl;
		cout << endl;
		unordered_set<int> s2(s);
		cout << "s2.size() :" << s2.size() << endl;

		cout << "s2.bucket_count():" << s2.bucket_count() << endl;
		cout << "s2.bucket_size(3):" << s2.bucket_size(3) << endl;
		cout << endl;

		unordered_set<int> s3;
		s3 = s2;
		cout << "s3.size() :" << s3.size() << endl;

		cout << "s3.bucket_count():" << s3.bucket_count() << endl;
		cout << "s3.bucket_size(3):" << s3.bucket_size(3) << endl;
		cout << endl;
	}
}
